package com.example.hyw.szysteam.arithmetic;

import android.util.Log;

import com.example.hyw.szysteam.POJO.Practice;

import java.util.ArrayList;

/**
 * Created by HYW on 2018/6/12.
 */

public class AcMain {
    public ArrayList<Practice> initPractice(int number,int operator,int range){
        ArrayList<Practice> practices=new ArrayList<Practice>();
        AC ac=new AC();
        RPN rpn=new RPN();
        Check check=new Check();
        for(int i=0;i<number;i++){
            ArrayList<Object> list=ac.createAc(operator,range);
            ArrayList<Object> right=rpn.toRPN(list);
            Tree tree=new Tree();
            tree=tree.createTree(right);
            if(check.checkRPN(tree.toString()) && check.checkAnswer(tree.getValue())){
                Practice practice=new Practice();
                practice.setQuestion(ac.toString(list));
                practice.setAnswer(tree.getValue().toString());
                practices.add(practice);
            }else {
                i--;
            }
        }
        return practices;
    }
}
